package sayai.mytest;

import java.net.URL;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;
import org.jdom.input.SAXBuilder;

public class ReadXML

{

	public static void main(String[] args) throws Exception

	{
		// URL url = new URL("c:\\temp\\test.xml");
		// ReadXML r= new ReadXML();
		// r.parse(url);
		SAXBuilder builder = new SAXBuilder();

		org.jdom.Document read_doc = builder.build("c:\\temp\\test.xml");

		org.jdom.Element stu = read_doc.getRootElement();

		List list = stu.getChildren("student");

		for (int i = 0; i < list.size(); i++)

		{

			org.jdom.Element e = (org.jdom.Element) list.get(i);

			String str_number = e.getChildText("number");

			String str_name = e.getChildText("name");

			String str_age = e.getChildText("age");

			System.out.println("---------STUDENT--------------");

			System.out.println("NUMBER:" + str_number);

			System.out.println("NAME:" + str_name);

			System.out.println("AGE:" + str_age);

			System.out.println("------------------------------");

			System.out.println();

		}
	}

	public Document parse(URL url) throws DocumentException {
		SAXReader reader = new SAXReader();
		Document document = reader.read(url);
		return document;

	}
}
